package PysicalSurfacesObjects;


import Basics.my3DPoint;
import Basics.myVector;
import def.IAllSceneObjects;
import def.Parser.ParseException;
import def.Ray;
import def.Intersection;
import def.ourParser;

public class Rectangle extends Entity implements IEntity, IAllSceneObjects{
	
	private my3DPoint p0;
	private my3DPoint p1;
	private my3DPoint p2;
	
	private myVector vecp0p1;
	private myVector vecp2p0;
	
	private myVector normal; 
	
	@Override
	public boolean setParameter(String name, String[] args) throws ParseException {
		
		int numOfArgs = args.length;
		
		if (!super.setParameter(name, args)) return false;
		
		switch(name) {
		
		case "p0":
			if (numOfArgs!=3) return false;
			this.p0 = new my3DPoint(ourParser.parseArrayOfDoubles(args)); 
			return true;
		case "p1":
			if (numOfArgs!=3) return false;
			this.p1 = new my3DPoint(ourParser.parseArrayOfDoubles(args));
			return true;
		case "p2":
			if (numOfArgs!=3) return false;
			this.p2 = new my3DPoint(ourParser.parseArrayOfDoubles(args));
			return true;
		default: return false;

		}
	
	}
	public Rectangle () {		
	}
	
	public Rectangle (my3DPoint p0, my3DPoint p1, my3DPoint p2) {
		
		this.p0 = new my3DPoint(p0);
		this.p1 = new my3DPoint(p1);
		this.p2 = new my3DPoint(p2);
		this.vecp0p1 = new myVector(p1, p0);
		this.vecp2p0 = new myVector(p2, p0);
		this.normal = vecp0p1.crossProduct(vecp2p0).normalize();		
		confirmObjectConditions();
		
	}
	
	
	@Override
	public boolean confirmObjectConditions(){
		if (!super.confirmObjectConditions()) return false;
		//Check if points are collinear
		if (this.p0.isCollinearTo(p1, p2)) return false;	
		return true; 
		
		
		
	}
	@Override
	public Intersection getIntersection(Ray ray) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Intersection Intersect(Ray ray) {
		// TODO Auto-generated method stub
		return null;
	}
	

}
